// 快排/ 插入排序
// flat 

function  quickSort(nums){
    let left = []
    let right = []
    let datum = nums[0]
    if(!nums.length) return []
    for(let i = 1; i< nums.length; i++){
        if(nums[i] > datum){
            right.push(nums[i])
        } else {
            left.push(nums[i])
        }
    }
    return quickSort(left).concat(datum, quickSort(right))
}
console.log(quickSort([ 3, 4, 1, 5, 2 ]))


function insetSort(nums){
    for(let i = 0; i< nums.length; i++){
        let temp = nums[i]
        let j = i - 1

        while(j >= 0 && nums[j] > temp){
            nums[j+1] = nums[j]
            j--            
        }
        nums[j+1] = temp
    }
    return nums
}
console.log(insetSort([ 3, 4, 1, 5, 2 ]))


Array.prototype.myFlat = function(dep){
    let res = []
    for(let i = 0; i < this.length; i++){
        if(Array.isArray(this[i]) && dep > 0){
            res = res.concat(this[i].myFlat(dep - 1))
        } else {
            res.push(this[i])
        }
    }
    return res;
}

console.log([1, [2, [3, 3]]].flat(2))
console.log([1, [2, [3, 3]]].myFlat(2))